
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:reabampos/src/reabam/operation/rb_config.dart';
import 'package:reabampos/src/reabam/ui/support/support_upload_order_paylist.dart';
import 'package:reabampos/src/reabam/ui_self_service/mine/pagestate_ss_setting.dart';
import 'package:reabampos/src/reabam/ui_self_service/pagestate_ss_login.dart';
import 'package:reabampos/src/reabam/utils/rb_color.dart';
import 'package:reabampos/src/reabam/utils/rb_widget_ss.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_string.dart';
import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';

/*
未上传(追平)订单
 */
class PageStateSelfServiceUploadOrder extends XPageListViewState{

  PageStateSelfServiceUploadOrder();

  @override
  Widget getListItemWidget(listItem, int position) {

    String fastOrderNo=listItem['fastOrderNo']??'';
    String orderMsg=listItem['orderMsg']??'';
    bool synSuccess=listItem['synSuccess']??false;
    bool businessSuccess=listItem['businessSuccess']??false;
    dynamic totalQuantity=listItem['totalQuantity']??0;
    dynamic totalMoney=listItem['totalMoney']??0;
    dynamic createDate='${listItem['createDate']}'.length>19?'${listItem['createDate']}'.substring(0,19):listItem['createDate'];

    return XWidgetUtils.getXLayoutRoundedRect(
        radius_bottomLeft: 16,
        radius_bottomRight: 16,
        radius_topRight: 16,
        radius_topLeft: 16,
        padding: XWidgetUtils.getEdgeInsets(30, 38, 30, 38),
        margin: XWidgetUtils.getEdgeInsets(0, 10, 0, 10),
        child: XWidgetUtils.getLayoutColumn(
            shrinkWrap:true,
            children: [
              XWidgetUtils.getLayoutRow(
                  children: [
                    XWidgetUtils.getWidgetText(
                        fastOrderNo,
                        style: XStyleUtils.getTextStyle(
                            fontSize:34,
                            color: XColorUtils.color333333,
                            fontWeight: FontWeight.bold,
                            lineHeight: 1
                        ),
                        padding: XWidgetUtils.getEdgeInsets(0, 0, 20, 0)
                    ),
                    XWidgetUtils.getWidgetText(
                        '已收银',
                        style: XStyleUtils.getTextStyle(
                            fontSize:34,
                            color: RBColors.reabamColor4,
                            lineHeight: 1
                        ),
                        padding: XWidgetUtils.getEdgeInsets(0, 0, 20, 0)
                    ),
                    XWidgetUtils.getWidgetText(
                        synSuccess?(businessSuccess?'已完成':'未同步'):'未上传',
                        style: XStyleUtils.getTextStyle(
                            fontSize:34,
                            color: const Color(0xFFF7AD08),
                            lineHeight: 1
                        )
                    ),
                    const Spacer(),
                    XWidgetUtils.getWidgetGestureDetector(
                        child:XWidgetUtils.getXLayoutRoundedRectWithBorder(
                            width: 122,
                            height: 44,
                            alignment: Alignment.center,
                            radius_bottomLeft: 8,
                            radius_bottomRight: 8,
                            radius_topRight: 8,
                            radius_topLeft: 8,
                            backgroundColor: Colors.white,
                            borderColor: RBColors.reabamColor4,
                            child: XWidgetUtils.getWidgetText(
                              synSuccess?'刷新':'上传',
                              style: XStyleUtils.getTextStyle(
                                fontSize: 28,
                                color: RBColors.reabamColor4,
                                lineHeight: 1,
                              ),
                              textAlign: TextAlign.center,
                            )
                        ),
                        onTap: (){
                          XLogUtils.printLog('---刷新本地未追平订单 retryPosOrder,orderNo=$fastOrderNo}');
                          SupportUploadOrderAndPay.retryPosOrder(fastOrderNo,(Map<String,dynamic> result){
                            //String json=XJsonUtils.obj2Json(result);
                            //XLogUtils.printLog('---retryPosOrder=$json');
                            String msg=result['msg'];
                            toast(msg);
                          });
                        }
                    )
                  ]
              ),
              XWidgetUtils.getLayoutContainer(
                margin: XWidgetUtils.getEdgeInsets(0, 15, 0, 0),
                child: XWidgetUtils.getLayoutRow(
                    children: [
                      XWidgetUtils.getLayoutContainer(
                        width: XTempData.defaultLeftKeyWidth,
                        child: XWidgetUtils.getWidgetText(
                          '实收金额',
                          style: XStyleUtils.getTextStyle(
                            fontSize:30,
                            color: XColorUtils.color666666,
                          ),
                        ),
                      ),
                      XWidgetUtils.getWidgetText(
                        '¥${XNumberUtils.formatDoubleX(totalMoney,n: 2)}',
                        style: XStyleUtils.getTextStyle(
                          fontSize:30,
                          color: XColorUtils.color666666,
                        ),
                      ),
                    ]
                ),
              ),
              XWidgetUtils.getLayoutContainer(
                margin: XWidgetUtils.getEdgeInsets(0, 10, 0, 0),
                child: XWidgetUtils.getLayoutRow(
                    children: [
                      XWidgetUtils.getLayoutContainer(
                        width: XTempData.defaultLeftKeyWidth,
                        child: XWidgetUtils.getWidgetText(
                          '购买商品',
                          style: XStyleUtils.getTextStyle(
                            fontSize:30,
                            color: XColorUtils.color666666,
                          ),
                        ),
                      ),
                      XWidgetUtils.getWidgetText(
                        XNumberUtils.formatDoubleX(totalQuantity),
                        style: XStyleUtils.getTextStyle(
                          fontSize:30,
                          color: XColorUtils.color666666,
                        ),
                      ),
                    ]
                ),
              ),
              XWidgetUtils.getLayoutContainer(
                margin: XWidgetUtils.getEdgeInsets(0, 10, 0, 0),
                child: XWidgetUtils.getLayoutRow(
                    children: [
                      XWidgetUtils.getLayoutContainer(
                        width: XTempData.defaultLeftKeyWidth,
                        child: XWidgetUtils.getWidgetText(
                          '创建时间',
                          style: XStyleUtils.getTextStyle(
                            fontSize:30,
                            color: XColorUtils.color666666,
                          ),
                        ),
                      ),
                      XWidgetUtils.getWidgetText(
                        '${createDate??''}',
                        style: XStyleUtils.getTextStyle(
                          fontSize:30,
                          color: XColorUtils.color666666,
                        ),
                      ),
                    ]
                ),
              ),
              XStringUtils.isEmpty(orderMsg)?XWidgetUtils.getLayoutContainer():XWidgetUtils.getWidgetText(
                orderMsg,
                style: XStyleUtils.getTextStyle(
                  fontSize:30,
                  color: const Color(0xFFFF0020),
                ),
                padding: XWidgetUtils.getEdgeInsets(0, 15, 0, 0),
              ),
            ]
        )
    );
  }

  @override
  void onStart() {

    setXTopBarWidget(
        height: null,
        child: RBWidgets_SelfService.getTitleBarWidget(
          this,
          title: '未上传订单',
        )
    );


  }

  @override
  Future<void> updateData({int pageIndex = 1}) async {

    Map<String,dynamic> uploadOrderRequest={};
    uploadOrderRequest['pageIndex']=pageIndex;
    uploadOrderRequest['pageSize']=20;
    SupportUploadOrderAndPay.getUploadOrderList(uploadOrderRequest,(Map<String,dynamic> result){
      //
      setXListData_pageIndexData(result['PageIndex'], result['PageCount'], result['items']);
    });

  }



  @override
  bool getIsEnablePageLoadData() {
    return true;
  }

  @override
  EdgeInsets getListViewPadding() {
    return XWidgetUtils.getEdgeInsets(30, 10, 30, 10);
  }



}